﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SWDataDB.DAL;
using SWDataDB.BLL;
using System.Data;

public partial class Admin_ZLManage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            bind();
        }
    }


    private void bind()
    {
        ZLInfo zlquery = new ZLInfo();

        DataSet ds = zlquery.GetAllInfoWithSet();
        DataTable dt = ds.Tables[0];
        DataView dv = dt.DefaultView;
        //对用于分页的类的引用
        PagedDataSource pds = new PagedDataSource();
        pds.DataSource = dt.DefaultView;//设置数据源(DataTable类型)
        pds.AllowPaging = true;


        AspNetPager1.RecordCount = dv.Count;
        pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
        pds.PageSize = AspNetPager1.PageSize;
        ZLRepeater.DataSource = pds;
        ZLRepeater.DataBind();
    }






    protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
    {
        AspNetPager1.CurrentPageIndex = e.NewPageIndex;
        bind();
    }



 

   


    protected void ZLRepeater_ItemCommand(object source, RepeaterCommandEventArgs e)
    {

        if (e.CommandName.Equals("DelData"))
        {
            ZLInfo zlDel = new ZLInfo();
            int delId = Convert.ToInt32(e.CommandArgument);
            if (zlDel.DeleteZLInfoByID(delId) == 1)
            {
                bind();
                Response.Write("<script language=javascript>alert('删除成功！');location='ZLManage.aspx'</script>");
                //Response.Redirect("ZLManage.aspx");
            }
            else
            {
                Response.Write("<script language=javascript>alert('删除失败！');location='ZLManage.aspx'</script>");
            }
        }

        

    }




    //批量删除
    protected void btnDel_Click(object sender, EventArgs e)
    {
       //先遍历取得选中项
        for (int i = 0; i < this.ZLRepeater.Items.Count; i++)
        {
            CheckBox cbx = (CheckBox)ZLRepeater.Items[i].FindControl("cbx");
            Label lbl = (Label)ZLRepeater.Items[i].FindControl("LBL");



            if (cbx != null)
            {
                if (cbx.Checked)
                {
                     ZLInfo zlDels = new ZLInfo();
                     string id = lbl.Text.ToString();
                     int delIds = Convert.ToInt32(id);
                     zlDels.DeleteZLInfoByID(delIds);
                }
            }
        }
        
        bind();
    }
 

     
    protected void SearchBtn_Click(object sender, ImageClickEventArgs e)
    {
        ZLInfoQuery zlquery = new ZLInfoQuery();
        string strTitle = Request.Form["TITLE"];
        string strFileID = Request.Form["FILE_ID"];
        string strKeyWord = Request.Form["KEY_WORDS"];
        string strUnit = Request.Form["UNIT"];
        string strType = Request.Form["DATA_CLASS"];
        string strWorkLevel = Request.Form["WORK_LEVEL"];
        string strMine = Request.Form["MineType"];
        string strRegion = Request.Form["XZArea"];
        string start = Request.Form["START_DATE"];
        string end = Request.Form["END_DATE"];

        //dl_FileList.DataSource = zlquery.ZLInfoAdvanceQueryKC(strTitle, strFileID, strKeyWord, strUnit, strType, strWorkLevel, strMine, strRegion, start, end);
        //dl_FileList.DataBind();
        DataSet ds = zlquery.ZLInfoAdvanceQueryKC(strTitle, strFileID, strKeyWord, strUnit, strType, strWorkLevel, strMine, strRegion, start, end);
        DataTable dt = ds.Tables[0];
        DataView dv = dt.DefaultView;
        //对用于分页的类的引用
        PagedDataSource pds = new PagedDataSource();
        pds.DataSource = dt.DefaultView;//设置数据源(DataTable类型)
        pds.AllowPaging = true;


        AspNetPager1.RecordCount = dv.Count;
        pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
        pds.PageSize = AspNetPager1.PageSize;
        ZLRepeater.DataSource = pds;
        ZLRepeater.DataBind();
    }


}